package character.writer;

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileWriteDemo1 {
    public static void main(String[] args) throws IOException {
        FileWriter fw=new FileWriter("b.txt",true);
        fw.write(97);
        fw.write("你好");
        fw.write("哈哈哈哈哈",0,2);
        char[] chs={'a','b','c'};
        fw.write(chs);
        fw.write(chs,0,2);
//        字符输出流要关流，否则数据写入不进去，如果用fw.flush()也可以刷新数据进去
        fw.flush();
        fw.write("中国人");
        fw.close();
//        int i =fr.read();
//        System.out.println(i);
//        fr.close();
//        fw.close();

//        FileWriter fw2=new FileWriter("b.txt");
//        fw.write("你好");
//        fw.close();
////        FileReader fr2=new FileReader("b.txt");
//        int i2 =fr.read();
//        System.out.println(i2);
//        fr2.close();
//        fw2.close();



        FileReader fr=new FileReader("b.txt");
        int i;
        char[] chs2=new char[1024];
        while((i=fr.read(chs2))!=-1){
            System.out.println(String.valueOf(i));
            String s=new String(chs2,0,i);
            System.out.println(s);
        }


    }
}
